#include<stdio.h>
#include<pthread.h>

int count = 0;
int n = 100000;
pthread_mutex_t m;

void *product(void *p){
	while(1){
		if(count >= n) continue;
		else{
			pthread_mutex_lock(&m);
			count +=1;
			printf("%d\n", count);
			pthread_mutex_unlock(&m);
		}
	}
}

void *consume(void *p){
	while(1){
		if(count == 0) continue;
		else{
			pthread_mutex_lock(&m);
			count -=1;
			printf("%d\n", count);
			pthread_mutex_unlock(&m);
		}
	}
}

int main(){
	pthread_t tt1,tt2;
	pthread_mutex_init(&m, NULL);
	pthread_create(&tt1,NULL,product,NULL);
	pthread_create(&tt2,NULL,consume,NULL);
	pthread_join(tt1,NULL);
	pthread_join(tt2,NULL);
}
